package com.zj.leetcode;

public class A28找出字符串中子串下标位置 {
    public static void main(String[] args) {
        String s1="123541";
        String s2="354";
        int res=strStr(s1,s2);
        System.out.println(res);
    }


    public static  int strStr(String haystack, String needle) {
        char[] s1=haystack.toCharArray();
        char[] s2=needle.toCharArray();
        for(int i=0;i<s1.length;i++){
            for(int j=0;j<s2.length&&(i+j)<s1.length;){
                if(s1[i+j]==s2[j]){
                    if((j==s2.length-1)){
                        return i;
                    }
                    j++;
                }else {
                    break;
                }

            }
        }
        return -1;
    }
}
